package com.turing.data.scripts.contract.transfer

import com.turing.common.util.StringUtils
import com.turing.data.vo.out.review.DependParamsVO
import com.turing.data.vo.out.review.TaskElementVO

class ClosedPeriod_30184_10_transfer {

    static List< TaskElementVO.DrawResultVO > doConvert(List< TaskElementVO.DrawResultVO > resultVOs, DependParamsVO dependParams){
        for( drawResultVO in resultVOs ) {
                def childTaskSn = drawResultVO.childTaskSn
                if(null == childTaskSn || childTaskSn == ""){
                    continue
                }
            String modelValue = drawResultVO.text
            String REGEX_CLOSED_1 = /.*封闭式.*/
            String REGEX_CLOSED_2 = /.*封闭运作.*/
            String REGEX_OTHER_2 = /.*定期开放.*/
            String REGEX_OTHER_3 = /.*开放.*次.*/
            String REGEX_OPEN_WEEKLY = /.*每周.*开放.*/
            String REGEX_OPEN_MONTHLY_1 = /.*每月.*开放.*/
            String REGEX_OPEN_MONTHLY_2 = /.*每个月.*开放.*/
            String REGEX_OPEN_1 = /.*无封闭.*/
            String REGEX_OPEN_2 = /.*始终开放.*/
            String REGEX_OPEN_3 = /.*成立.*个月.*/
            String REGEX_ONE_MOST_1= /.*满.*年开放一次.*/
            String REGEX_ONE_MOST_2= /.*满.*\d月开放一次.*/

            if (  modelValue =~ REGEX_ONE_MOST_1  ) {
                drawResultVO.businessValue = "3个月最多一次"
                drawResultVO.type = 1
            } else if ( modelValue =~ REGEX_ONE_MOST_2 ) {
                try {
                    def nums = modelValue.findAll(/\d/) as int[]
                    def num = 0
                    for(number in nums){
                        num = number
                    }
                    if(num >= 3){
                        drawResultVO.businessValue = "3个月最多一次"
                        drawResultVO.type = 1
                    }
                } catch (Exception e) {
                    e.printStackTrace()
                    drawResultVO.businessValue = "3个月最多一次"
                    drawResultVO.type = 1
                }
            }else if (  modelValue =~ REGEX_OTHER_2 || modelValue =~ REGEX_OTHER_3 \
                || modelValue =~ REGEX_OPEN_WEEKLY || modelValue =~ REGEX_OPEN_MONTHLY_1 || modelValue =~ REGEX_OPEN_MONTHLY_2 ) {

                drawResultVO.businessValue = "其他（" + modelValue + "）"
                drawResultVO.type = 1

            } else if (modelValue =~ REGEX_CLOSED_1 || modelValue =~ REGEX_CLOSED_2) {
                drawResultVO.businessValue = "始终封闭运作"
                drawResultVO.type = 1
            }  else if (modelValue =~ REGEX_OPEN_1 || modelValue =~ REGEX_OPEN_2) {
                drawResultVO.businessValue = "无封闭期"
                drawResultVO.type = 1
            }else if (modelValue =~ REGEX_OPEN_3 ) {
                def nums = modelValue.findAll(/\d/) as int[]
                def num = ""
                for(number in nums){
                    num += number.toString()
                }
                drawResultVO.businessValue = "资产管理计划成立后" + num + "个月"
                drawResultVO.type = 1
            }else{
                if(!StringUtils.isEmpty(modelValue)){
                    drawResultVO.businessValue = "其他（" + modelValue + "）"
                    drawResultVO.type = 1
                }
            }
        }

        return resultVOs
    }

}
